/**
 * 
 */
package uk.ac.ebi.curtain.utils.file.maq;

/**
 * @author mhaimel
 *
 */
public enum MaqFlag {
	
	
//	# 0   - stands for Unpaired, 
//	# 1   - stands for FF, 
//	# 2   - for FR, 
//	# 4   - for RF, and 
//	# 8   - for RR,
//	# 16  - meets the paired end requirement
//	# 18  - flag for a correct pair
//	# 32  - two reads are mapped to different chromosomes
//	# 64  - one of the two reads cannot be mapped at all
//	# 130 - reads aligned by the Smith-Waterman
//	# 192 - read is not mapped but its mate is mapped (the other read has flag 64) 64)

	NotPaired(0,1),
	FF(1,2),
	FR(2,3),
	RF(4,4),
	RR(8,5),
	PairedExist(16,6),
	PairedCorrect(18,7),
	PairedCorrect2(20,14),
	ChromosomeDiff(32,8),
	PairedSingleMapped(64,9),
	SmAligned(130,10),
	PairedMatedMapped(192,11);
	
	private short id;
	private byte bVal;

	private MaqFlag(Integer id, Integer byteVal) {
		this.id = id.shortValue();
		this.bVal = byteVal.byteValue();
	}
	
	public static MaqFlag getFlag(Integer i){
		short s = i.shortValue();
		MaqFlag found = null;
		for(MaqFlag flag : values()){
			if(flag.id == s){
				found = flag;
				break;
			}
		}
		return found;
	}
	
	public static MaqFlag getFlag(byte b){
		MaqFlag found = null;
		for(MaqFlag flag : values()){
			if(flag.bVal == b){
				found = flag;
				break;
			}
		}
		return found;
	}

	public short getId() {
		return id;
	}
	
	public byte getByteVal() {
		return bVal;
	}		
	
	public static MaqFlag getFlat(boolean paired, boolean mapped, boolean otherMapped, boolean differentContig){
		if(!paired){
			return NotPaired;
		}
		if(!mapped || !otherMapped){
			if(mapped){
				return PairedSingleMapped;
			} else {
				return PairedMatedMapped;
			}
		} else if(differentContig) {
			return ChromosomeDiff;
		} else {
			return PairedCorrect;
		}
	}
}


